package com.ab;

/**
 * Created by IntelliJ IDEA.
 * User: Anna.Bulenkova
 * Date: 20.10.11
 * Time: 15:28

 */
class Deadlock {
    static class Issue {
        private final String name;
        public Issue(String name) {
            this.name = name;
        }
        public synchronized void sendRequest(Issue request) {
            System.out.println(this.name);
            request.sendReply(this);
        }
        public synchronized void sendReply(Issue reply) {
            System.out.println(this.name);
        }
    }

    public static void main(String[] args) {
        final Issue userRequest = new Issue("I have no internet connection!!!");
        final Issue supportTeamReply = new Issue("Please, send an e-mail to provider's support team");
        Thread user = new Thread() {
            public void run() {
                userRequest.sendRequest(supportTeamReply);
            }
        };
        Thread support = new Thread() {
            public void run() {
                supportTeamReply.sendRequest(userRequest);
            }
        };
        user.start();
        support.start();

    }
}